<?php

/**
 * @Author: DEEP-2018BRTYLP\Administrator
 * @Date:   2019-03-19 15:17:42
 * @Last Modified by:   DEEP-2018BRTYLP\Administrator
 * @Last Modified time: 2019-04-03 08:35:16
 */
namespace app\api\controller;
use app\common\model\Version;
use fast\Random;
use think\Config;
use app\api\controller\Base;
/**
 * 
 */
class Cate extends Base
{
	/*
		列表
	 */ 
	public function param()
	{
		$table = input('param.table','zodiac');
		$map['status'] = 'normal';
		$data = db($table)->where($map)->order('id desc')->cache(true,60)->field('id,name')->select();
		$data1 = [];
		foreach ($data as $key => $value) {
			$data2[$value['id']] = $value['name'];
			if($table == "question"){
				$data1[] = ['title'=>$value['name'],'id'=>$value['id'],'answer'=>''];
			}else{
				$data1[] = ['title'=>$value['name'],'value'=>$value['id']];
			}
		}
		if($data1){
			return $this->return_success('获取数据',['data1'=>$data1,'data'=>$data2],1);
		}else{
			return $this->return_error('暂无数据',[],0);
		}
	}

	/**
	 * 保存标签
	 */
	public function save_tags(){
		$uid  = input('param.uid',1);
		$tags = input('param.tags');
		$re = db('member')->where(['id'=>$uid])->update(['tags_ids'=>$tags,'last_login_time'=>time()]);
		if($re){
			return $this->return_success('保存成功',[],1);
		}else{
			return $this->return_error('保存失败',[],0);
		}
	}

	/**
	 * 获取我的标签
	 */
	public function my_tag(){
		$uid  = input('param.uid',1);
		$tags_ids = db('member')->where(['id'=>$uid])->value('tags_ids');
		$tags_ids_arr1 = explode(',',$tags_ids);
		$tags = db('tags')->select();
		$tags_name = [];
		foreach ($tags_ids_arr1 as $key => $val) {
			$tags_ids_arr[] = (int)$val;
		}
		foreach ($tags_ids_arr as $key => $value) {
			foreach ($tags as $key => $val) {
				if($val['id'] == $value){
					$tags_name[] = $val['name'];
					continue;
				}
			}
		}
		return $this->return_success('获取数据成功！',['tags_ids'=>$tags_ids_arr,'tags_name'=>$tags_name],1);
	}
}
